package com.kedacom.demo.modularity.message;

import java.util.ArrayList;
import java.util.List;

import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.jaxrs.provider.json.JSONProvider;

import com.kedacom.demo.modularity.core.BusinessExceptionMapper;

public class XMPPMessageGatewayRunnable implements Runnable {

	private String url;

	public XMPPMessageGatewayRunnable(String url) {
		super();
		this.url = url;
	}

	@Override
	public void run() {
		JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
		sf.setResourceClasses(XMPPMessageGateway.class);
		sf.setResourceProvider(XMPPMessageGateway.class, new SingletonResourceProvider(new XMPPMessageGatewayImpl()));
		List<Object> providers = new ArrayList<Object>();
		providers.add(new JSONProvider<Object>());
		providers.add(new BusinessExceptionMapper());
		sf.setProviders(providers);
		sf.setAddress(url);
		sf.create();
	}

}
